{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#Series (collection of values)\n",
    "#DataFrame (collection of Series objects)\n",
    "#Panel (collection of DataFrame objects)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#A Series object can hold many data types, including\n",
    "#float - for representing float values\n",
    "#int - for representing integer values\n",
    "#bool - for representing Boolean values\n",
    "#datetime64[ns] - for representing date & time, without time-zone\n",
    "#datetime64[ns, tz] - for representing date & time, with time-zone\n",
    "#timedelta[ns] - for representing differences in dates & times (seconds, minutes, etc.)\n",
    "#category - for representing categorical values\n",
    "#object - for representing String values\n",
    "\n",
    "#FILM - film name\n",
    "#RottenTomatoes - Rotten Tomatoes critics average score\n",
    "#RottenTomatoes_User - Rotten Tomatoes user average score\n",
    "#RT_norm - Rotten Tomatoes critics average score (normalized to a 0 to 5 point system)\n",
    "#RT_user_norm - Rotten Tomatoes user average score (normalized to a 0 to 5 point system)\n",
    "#Metacritic - Metacritic critics average score\n",
    "#Metacritic_User - Metacritic user average score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "fandango = pd.read_csv('fandango_score_comparison.csv')\n",
    "series_film = fandango['FILM']\n",
    "print(series_film[0:5])\n",
    "series_rt = fandango['RottenTomatoes']\n",
    "print (series_rt[0:5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Import the Series object from pandas\n",
    "from pandas import Series\n",
    "\n",
    "film_names = series_film.values\n",
    "#print type(film_names)\n",
    "#print film_names\n",
    "rt_scores = series_rt.values\n",
    "#print rt_scores\n",
    "series_custom = Series(rt_scores , index=film_names)\n",
    "series_custom[['Minions (2015)', 'Leviathan (2014)']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# int index is also aviable\n",
    "series_custom = Series(rt_scores , index=film_names)\n",
    "series_custom[['Minions (2015)', 'Leviathan (2014)']]\n",
    "fiveten = series_custom[5:10]\n",
    "print(fiveten)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "original_index = series_custom.index.tolist()\n",
    "#print original_index\n",
    "sorted_index = sorted(original_index)\n",
    "sorted_by_index = series_custom.reindex(sorted_index)\n",
    "#print sorted_by_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "sc2 = series_custom.sort_index()\n",
    "sc3 = series_custom.sort_values()\n",
    "#print(sc2[0:10])\n",
    "print(sc3[0:10])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#The values in a Series object are treated as an ndarray, the core data type in NumPy\n",
    "import numpy as np\n",
    "# Add each value with each other\n",
    "print np.add(series_custom, series_custom)\n",
    "# Apply sine function to each value\n",
    "np.sin(series_custom)\n",
    "# Return the highest value (will return a single value not a Series)\n",
    "np.max(series_custom)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#will actually return a Series object with a boolean value for each film\n",
    "series_custom > 50\n",
    "series_greater_than_50 = series_custom[series_custom > 50]\n",
    "\n",
    "criteria_one = series_custom > 50\n",
    "criteria_two = series_custom < 75\n",
    "both_criteria = series_custom[criteria_one & criteria_two]\n",
    "print both_criteria"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#data alignment same index\n",
    "rt_critics = Series(fandango['RottenTomatoes'].values, index=fandango['FILM'])\n",
    "rt_users = Series(fandango['RottenTomatoes_User'].values, index=fandango['FILM'])\n",
    "rt_mean = (rt_critics + rt_users)/2\n",
    "\n",
    "print(rt_mean)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
